package com.blockchain.console.servlets.trading.jjfq;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.IsPass;
import com.blockchain.console.service.trading.TradingManage;
import com.blockchain.console.service.trading.entity.JyfqEntity;
import com.blockchain.console.service.trading.entity.XlbEntity;
import com.blockchain.console.service.trading.query.JyfqQuery;
import com.blockchain.console.servlets.trading.AbstractTradingServlet;
import com.blockchain.framework.http.servlet.annotation.Right;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;

@Right(id = "C_TRADING_UPDATEJYFQ", name = "交易管理-编辑")
public class UpdateJyfq extends AbstractTradingServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		int id = IntegerParser.parse(request.getParameter("id"));
		JyfqEntity jys=tsradingManage.getJyfq(id);
		XlbEntity [] xlb=tsradingManage.getXlbxx();
		request.setAttribute("jys", jys);
		request.setAttribute("xlb", xlb);
		forwardView(request, response, getClass());

	}

	@Override
	protected void processPost(final HttpServletRequest request, final HttpServletResponse response,
			final ServiceSession serviceSession) throws Throwable {
			int id = IntegerParser.parse(request.getParameter("fqid"));
			TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
			tsradingManage.updateJyfq(new JyfqQuery() {
			@Override
			public IsPass sfky() {
				return EnumParser.parse(IsPass.class, request.getParameter("sfky"));
			}

			@Override
			public int getPx() {
				return IntegerParser.parse(request.getParameter("px"));
			}

			@Override
			public String getFqywm() {
				return request.getParameter("fqywm");
			}

			@Override
			public String getFqmc() {
				return request.getParameter("fqmc");
			}

			@Override
			public int getBid() {
				return IntegerParser.parse(request.getParameter("bid"));
			}
		}, id);
		sendRedirect(request, response, getController().getURI(request, JyfqList.class));
	}

}
